/**
 * FIFS - The Find It File System
 * Copyright (C) 2006 Chris Oklota (chris at oklota dot net)
 * 
 * This program is distributed under the terms of the GNU LGPL.
 * See the file http://www.gnu.org/licenses/lgpl.txt
 */
package fifs;

import java.io.FileInputStream;
import java.util.Properties;

import org.apache.log4j.PropertyConfigurator;

import fuse.FuseMount;

public class FifsMockFilesystem extends Fifs {

    /**
     * Mainline for filesystem in user space
     * 
     * @param args
     *            Command line arguments, must include mount point
     */
    public static void main(String[] args) {

        // first thing, initialize the logging subsystem
        PropertyConfigurator.configure(CONFIG_FILE);

        // must specify mount point on command line
        if (args.length < 3) {
            log.error("Must at least specify mount point on command line");
            System.exit(-1);
        }

        log.info("Starting fifs");
        for (int i = 0; i < args.length; i++) {
            log.trace("arg[" + i + "] = \"" + args[i] + "\"");
        }
        
        try {

            Fifs fifs = new FifsMockFilesystem();

            // load the properties from the config file
            Properties props = new Properties();
            props.load(new FileInputStream(CONFIG_FILE));
            fifs.setProperties(props);

            // create an implementation of the dao that's all in memory
            FifsDao dao = new FifsMockDaoImpl();
            fifs.setDao(dao);

            // set the mount point (the last command line argument)
            fifs.setMountPoint(args[args.length-1]);

            // mount the filesystem
            FuseMount.mount(args, fifs);

        } catch (Exception e) {
            log.error("Error with fifs: ", e);
        } finally {
            log.info("Exiting fifs");
        }
    }
}
